using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using JuegoBomberman.Controladores;
using JuegoBomberman.Vistas;
using JuegoBomberman.Menu;
using Modelo;

namespace JuegoBomberman
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class JuegoBomberman : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        IDibujable vistaActual;
        Dictionary<String, IDibujable> coleccionVistas;



        public JuegoBomberman()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferHeight = 661;
            graphics.PreferredBackBufferWidth = 705;
            this.IsFixedTimeStep = true;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            this.coleccionVistas = new Dictionary<string, IDibujable>();
            this.coleccionVistas.Add("menuPrincipal", new MenuPrincipal(this));
            this.coleccionVistas.Add("menuGameOver", new MenuGameOver(this));
            this.coleccionVistas.Add("menuGanaste", new MenuGanaste(this));

            this.vistaActual = this.coleccionVistas["menuPrincipal"];
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // TODO: use this.Content to load your game content here
            this.coleccionVistas["menuPrincipal"].LoadContent();
            this.coleccionVistas["menuGameOver"].LoadContent();
            this.coleccionVistas["menuGanaste"].LoadContent();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Actualizo mi vista actual.
            this.vistaActual.Update(gameTime);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
             {
            // Le digo a mi vista que se dibuje.
            this.vistaActual.Draw(gameTime);
        }

        public void inicializarJuego()
        {
            if (this.coleccionVistas.ContainsKey("partida"))
            {
                this.coleccionVistas["partida"] = new PartidaVista(this,false);
            }
            else
            {
                this.coleccionVistas.Add("partida", new PartidaVista(this, false));
            }
            this.vistaActual = this.coleccionVistas["partida"];
        }

        public void MostrarMenuPrincipal()
        {
            this.vistaActual = this.coleccionVistas["menuPrincipal"];
        }

        public void RecuperarPartidaGuardada()
        {

            ((PartidaVista)this.coleccionVistas["partida"]).RecuperarPartida(this);
        }

        public void MostrarGameOver()
        {
            this.vistaActual = this.coleccionVistas["menuGameOver"];
        }
        public void MostrarGanaste()
        {
            this.vistaActual = this.coleccionVistas["menuGanaste"];
        }
    }
}
